<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>选择航班chooseFlight</title>
	</head>
	<link rel="stylesheet" href="../css/common.css" />
	<link rel="stylesheet" href="../css/less/common_less.css" />
	<style>
		
		.Dolo_searchPanle{
			width:1120px;			
		}
		.Dolo_searchPanle .ptop{
			line-height:50px;			
		}
		.Dolo_searchPanle .ptop span{
			margin-left:3px;
		}
		.Dolo_searchPanle .ptop span:nth-of-type(1){
			margin-left:20px;
		}
		.Dolo_searchPanle .ptop span input{
			margin-left:5px;
			height:21px;
			border:1px solid #e1e1eb;
			border-radius:3px;
			width:125px;
		}
		.Dolo_btn{
			float:right;
			margin-right:20px;
			margin-top:12px;
		}
		.checkPanle{
			width:1120px;
			height:47px;
			margin-left:4px;
			margin-top:30px;			
		}
		.checkPanle p{
			height:46px;
			line-height:46px;
		}
		.checkPanle p span:first-child{
			margin-left:20px;
		}
		.checkPanle p span:first-child input{
			position:relative;
			top:5px;
		}
		.dataTable{
			background:white;
			margin-left:4px;
			width:1120px;
		}
		.dataTable table{
			border-collapse:collapse;
			width:1100px;
		}
		.dataTable table td{
			height:50px;
		}
		.dataTable table tr th{
			font-weight:normal;
		}
		
		.dataTable .clear tr{
			border-top:5px solid #f1f1f1;
		}
		.topTr{
			height:40px;
			background:white;
			border-top:1px solid #f1f1f1;
			border-bottom:1px solid #f1f1f1;
		}
		.fontColor{
			color:#00aa98;
		}
		.check{
			float:left;
			margin-left:15px;
		}
		.pbottom{
			height:35px;
			line-height:35px;
			background:white;
			border-top:1px solid #ececec;
		}
		.derWeek{
			margin-left:25px;
		}
		.derWeek input[type=checkbox]{			
			margin-left:15px;
			position:relative;
			top:5px;
			right:5px;
		}
		input{
			font-family:"微软雅黑";
		}
		.query,.chooseFlight{
			margin-right:10px;
		}
	
		.exchangeAirportCode{
			cursor:pointer;
			font-size:14px;
		}
		.querySpan{
			float: right;
			margin-right: 20px;
			margin-top: 11px;
		}
		.font14px{
			font-size: 14px;
		}
	</style>
	<body>
		<div class='Dolo_searchPanle'>
			<p class='ptop f60666'>
				<span>航班号<strong style='color:red;font-size: 16px;'>*</strong><input uppercase class='airlineCode' type='text'/></span>
				<span>出发起始日期<input class='datespicker startDate' onFocus="new WdatePicker({dateFmt:'yyyy-MM-dd'})" type='text'/></span>
				<span>出发结束日期<input class='datespicker endDate' onFocus="new WdatePicker({dateFmt:'yyyy-MM-dd'})" type='text'/></span>	
				<span>出发机场<strong style='color:red;font-size: 16px;'>*</strong><input uppercase class='queryDep dep autocomplete' type='text' /><i style='display:none;' class='hiddeDepInput'></i></span>	
				<span class='iconfont exchangeAirportCode'>&#xe719;</span>	
								
				<span>到达机场<strong style='color:red;font-size: 16px;'>*</strong><input uppercase class='queryArr arr autocomplete' type='text' /><i style='display:none;' class='hiddeArrInput'></i></span>
							
		<!--		<button class='Dolo_btn query'>查询</button> -->
				<button class="querySpan searchBtn" id="query"><i class="iconfont setIcon">&#xe661;</i>查询</button>
			</p>
			<p class='pbottom f60666'>
				<span class='derWeek'>出发星期：
					<input class='checkAllWeek' type='checkbox' />全部
					<input value='1' class='checkWeek' type='checkbox' />周一
					<input value='2' class='checkWeek' type='checkbox' />周二
					<input value='3' class='checkWeek' type='checkbox' />周三
					<input value='4' class='checkWeek' type='checkbox' />周四
					<input value='5' class='checkWeek' type='checkbox' />周五
					<input value='6' class='checkWeek' type='checkbox' />周六
					<input value='7' class='checkWeek' type='checkbox' />周日
				</span>
			</p>
		</div>
		<div class='checkPanle'>
			<p>
				<span class="f60666 font14px"><input class='checkAll' type='checkbox'/> &nbsp;全选</span>
				<span><button class='Dolo_btn chooseFlight'>选择航班</button></span>
				
			</p>
		</div>
		<div class='dataTable'>
			<table id="dataTable">
				<thead>
					<tr class='topTr f868686'>
						<th>航班号</th>
						<th>出发机场</th>
						<th>到达机场</th>
						<th>出发时间</th>
						<th>到达时间</th>
						<th>星期</th>
					</tr>
				</thead>
				<tbody class='clear'></tbody>				
			</table>
		</div>		
		<!-- 分页 -->
		<div class='Pagination'></div>
	</body>
		<script type="text/javascript" src="../js/jquery-1.12.4.js" ></script>
		<script type="text/javascript" src="../js/jquery.freezeheader.js" ></script>
		<script type="text/javascript" src="../js/jquery.autocomplete.js" ></script>
		<script type="text/javascript" src="../layer-v2.4/layer/layer.js" ></script>
		<script type="text/javascript" src="../js/common.js" ></script>
		<!-- 引入my97日期时间控件 -->
		<script type="text/javascript" src="../js/My97DatePicker/WdatePicker.js" charset="utf-8"></script>	
		<script>
		//____________________________________________________________________________机场联想
		var autocompleteData=[];
		$.ajax({
			type:"get",
			url:"../Airapt?pageSize=100000&pageNum=1&temp="+Math.random(),
			dataType:"json",
			success:function(data){	
				autocompleteData = data.data.list; 
				$('.autocomplete').autocomplete({
				    lookup: autocompleteData,
				    autoSelectFirst:true,
				    onSelect: function (suggestion) {		   
				    }
				});
			}
		})

		//_________________________________________________________________搜索功能________
			$("#query").click(function(){
				$(".page").val("1");
				if($(".airlineCode").val()==""||$(".dep").val()==""||$(".arr").val()==""){
					layer.msg('请输入必填项',{icon:2,time:1000});
					return false;
				}
				getAjax();
			})
		
//________________________________________表头固定____________________________________________
		$("#dataTable").freezeHeader();	
		
//_________________________________________________________________封装Ajax_______
			var totalAmount
			var totalPage
			var nowPage
			function getAjax(){
				var airlineCode = ($(".airlineCode").val()).toUpperCase();
				var dayofweek = getDayOfWeek(); 
				var startDate = $(".startDate").val();
				var endDate = $(".endDate").val() ;
				if(/\((.)+?\)/.test($(".dep").val())){//获取出发机场三字码
					var queryDep = $(".dep").val().slice(-5).split("(")[1].split(")")[0];
				}else{
					var queryDep = ($(".dep").val()).toUpperCase();
				}
				if(/\((.)+?\)/.test($(".arr").val())){//获取到达机场三字码
					var queryArr = $(".arr").val().slice(-5).split("(")[1].split(")")[0];
				}else{
					var queryArr = ($(".arr").val()).toUpperCase();
				}
			
				
				
				var pageNum = $(".page").val();
				var pageSize = $(".pageSize").val();
				$.get("../fltSeg/api/segList?airlineCode="+airlineCode+"&dayofweek="+dayofweek+"&startDate="+startDate+"&endDate="+endDate+"&pageNum="+pageNum+"&dep="+queryDep+"&arr="+queryArr+"&pageSize="+pageSize+"&temp="+Math.random(),function(data){

					data = JSON.parse(data)	
					//console.log(data)
					totalAmount = data.data.total
					totalPage = data.data.pages
					nowPage = data.data.pageNum
					//共多少条
					$(".totalAmount").text(totalAmount)
					//共多少页
					$(".totalPage").text(totalPage)
					//第几页
					$(".nowPage").text(nowPage)
					$(".clear").empty();
					var str = "";
					//console.log(data)
					for(var i in data.data.list){
						str+="<tr>"+
								  "<td class='f60666'><input class='check' type='checkbox' /><span class='flightNo'>"+data.data.list[i].airlineCode+"</span><span class='flightId' style='color:red;display:none'>"+data.data.list[i].id+"</span></td>"+
								  "<td class='depAirport f60666'>"+data.data.list[i].depAirportName+"&nbsp;&nbsp;&nbsp;("+data.data.list[i].depAirport+")</td>"+
								  "<td class='arrAirport f60666'>"+data.data.list[i].arrAirportName+"&nbsp;&nbsp;&nbsp;("+data.data.list[i].arrAirport+")</td>"+
								  "<td class='f60666'><span class='DepDate'>"+data.data.list[i].depDate +"</span>&nbsp;<span class='f00aa99 depTime'>"+ data.data.list[i].depTime+"</span></td>"+
								  "<td class='f60666'><span class='ArrDate'>"+data.data.list[i].arrDate +"</span>&nbsp;<span class='f00aa99 arrTime'>"+ data.data.list[i].arrTime+"</span></td>"+
								  "<td class='dayofweekTd f60666'>"+data.data.list[i].dayofweek+"</td>"+
							 "</tr>"
					}
					$(".clear").append(str)
				})
			}
			
		//_________________________________________________________________返回给父页面的值_____________	
						
			$(".chooseFlight").click(function(){
				var messArr = [];
				var arr = [];
				var length = $(".clear input[type=checkbox]").length
				for(var i=0;i<length;i++){
					if($(".clear input:checkbox")[i].checked){
						arr.push(i)						
					}
				}
				for(var i=0;i<arr.length;i++){
					var mess = {};
					mess.id = $(".flightId").eq(arr[i]).text();
					mess.flightNo = $(".flightNo").eq(arr[i]).text();
					mess.depAirport = $(".depAirport").eq(arr[i]).text();
					mess.arrAirport = $(".arrAirport").eq(arr[i]).text();
					mess.DepDate = $(".DepDate").eq(arr[i]).text();
					mess.ArrDate = $(".ArrDate").eq(arr[i]).text();
					mess.dayofweek = $(".dayofweekTd").eq(arr[i]).text();
					mess.depTime = $(".depTime").eq(arr[i]).text();
					mess.arrTime = $(".arrTime").eq(arr[i]).text();
					messArr.push(mess);
				}
				//console.log(messArr)	
				if(messArr.length==0){
					layer.msg("请选择航班",{icon: 2,time:2000},function(){
						return false;
					})
				}else{
					window.parent.setData(messArr);
					layer.msg('选择航班成功', {icon: 1,time:1000},function(){
						var index = parent.layer.getFrameIndex(window.name);//获取弹窗索引
						parent.layer.close(index);//关闭弹窗	
					}) 
				}
				
				    
				
				
			})
			//___________________________________________________________获取选定的日期的字符串
			function getDayOfWeek(){
				var arr = [];
				var str = "";
				var length = $("input[class=checkWeek]").length
				for(var i=0;i<length;i++){
					if($("input[class=checkWeek]")[i].checked){
						arr.push(i)						
					}
				}
				for(var i=0;i<arr.length;i++){
					str+=$("input[class=checkWeek]").eq(arr[i]).val()+",";
				}
				str=str.substring(0,str.length-1)                        //去掉最后一个字符
				return str;
			}
			
			
			
//___________________________________________________________日期全选
			$(".checkAllWeek").click(function(){
				if(this.checked){
					$(".checkWeek").prop('checked','checked')				
				}else{
					$(".checkWeek").prop('checked',false)		
				}
			})
			
			
//____________________________________________出发到达机场条件互换________________
			$(".exchangeAirportCode").click(function(){
				var exchangeVar = $(".queryDep").val();
				$(".queryDep").val($(".queryArr").val());
				$(".queryArr").val(exchangeVar);
			})
//________________________________________分页__________________________________
	$(".Pagination").load("Pagination.html",function(){
		getAjax();
	})						
					
			
			
			
			
			
			
			
			
			
			
			
			
		
		</script>		
</html>
